home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************/
- /* DATABOSS MODULE: DB_FUNCS.C */
- /****************************************************************************/
-
- #include "db_lsc.h"
-
- #ifdef __TURBOC__
- #include <conio.h>
- #include "db_types.h"
- #include <dir.h>
- #else
- #include <graph.h>
- #include "db_types.h"
- #include "db_conio.h"
- #include <direct.h>
- #include <errno.h>
- #endif
- #include <dos.h>
- #include <io.h>
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "db_dos.h"
- #include "db_file.h"
- #include "db_key.h"
- #include "db_str.h"
- #include "db_funcs.h"
- #include "db_sets.h"
-
-
- /**************************** GLOBAL CONSTANTS ****************************/
-
- const uchar ToAlt[] = {
- 130,46,47,129,248,249,250,251,252,253,254,255,128,
- 58,59,60,131,62,63,64,
- 158,176,174,160,146,161,162,163,151,164,165,166,178,
- 177,152,153,144,147,159,148,150,175,145,173,149,172};
- set _ALPHA = {
- 0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFC,
- 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
- 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
- 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F};
- set _WORDSET = {
- 0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x03,
- 0xFE,0xFF,0xFF,0x07,0xFE,0xFF,0xFF,0x07,
- 0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
- set _DIGITS = {
- 0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x03,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
- set _SPLITSET = {
- 0x00,0x00,0x00,0x00,0x11,0xF7,0x00,0x04,
- 0x00,0x00,0x00,0x38,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
- set ExitSet = {
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x78,
- 0x1F,0x03,0xF3,0xFF,0xFF,0xFF,0xE3,0x00};
-
- const uchar HexDigit[] = "0123456789ABCDEF";
-
- set _NumFld = {
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x02,0x40,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-
- uchar LineStr[41] = "ÿœ—Δµ‘æ’∏◊–“«∂”Ω÷∑ŒÀ Ãπ»º…ªÕ∫≈¬¡√¥¿Ÿ⁄øƒ≥";
- set SLS = {'ƒ','¿','¡','¬','√','≈','«','–','“','”','÷','◊','⁄'};
- set SRS = {'ƒ','¥','∂','∑','Ω','ø','¡','¬','≈','–','“','◊','Ÿ'};
- set SUS = {'≥','¥','µ','∏','ø','¬','√','≈','Δ','—','’','ÿ','⁄'};
- set SDS = {'≥','¥','µ','æ','¿','¡','√','≈','Δ','œ','‘','ÿ','Ÿ'};
- set DLS = {'Õ','Δ','»','…',' ','À','Ã','Œ','œ','—','‘','’','ÿ'};
- set DRS = {'Õ','µ','∏','π','ª','º','æ',' ','À','Œ','œ','—','ÿ'};
- set DUS = {'∫','∂','∑','π','ª','«','…','À','Ã','Œ','“','÷','◊'};
- set DDS = {'∫','∂','π','º','Ω','«','»',' ','Ã','Œ','–','”','◊'};
-
- /********************** GLOBAL INITIALIZED VARIABLES **********************/
-
- byte _av = 112;
- byte _pv = 7;
- byte _iv = 7;
- byte _ev = 15;
- byte errcolr = 79;
- byte diratr = 0x70;
- byte edt_spos = 0;
- int _Tab_Space = 6;
-
- /*************************** INTERNAL VARIABLES ***************************/
-
- static bool initialized = False;
-
- /***************************** IMPLEMENTATION *****************************/
-
- bool nocheck(string instr)
- {
- return (True);
- }
-
- void nohelp(void)
- {
- }
-
- bool chkyesno(string instr)
- {
- return ((bool) ((*instr == _YES) || (*instr == _NO)));
- }
-
- void clr_line(byte y)
- {
- gotoxy(1,y);
- clreol();
- }
-
-
- void clearInputBuffer(void) /* SN 3.5 */
- { /* SN 3.5 */
- while(kpressed()) getkey(); /* SN 3.5 */
- return; /* SN 3.5 */
- } /* SN 3.5 */
-
- uchar smartCh(string startSet, uchar charA, uchar charB, uchar charC, uchar charD) /* SN 3.5 */
- {
- uchar tempChar; /* SN 3.5 */
- string tempSet; /* SN 3.5 */
- int counter; /* SN 3.5 */
-
- strcpy(tempSet, startSet); /* SN 3.5 */
- if (charA != ' ') { /* SN 3.5 */
- if (set_member(SUS, (byte)charA)) set_intersection(tempSet, tempSet, SDS); /* SN 3.5 */
- if (set_member(DUS, (byte)charA)) set_intersection(tempSet, tempSet, DDS); /* SN 3.5 */
- }
- if (charB != ' ') { /* SN 3.5 */
- if (set_member(SRS, (byte)charB)) set_intersection(tempSet, tempSet, SLS); /* SN 3.5 */
- if (set_member(DRS, (byte)charB)) set_intersection(tempSet, tempSet, DLS); /* SN 3.5 */
- }
- if (charC != ' ') { /* SN 3.5 */
- if (set_member(SDS, (byte)charC)) set_intersection(tempSet, tempSet, SUS); /* SN 3.5 */
- if (set_member(DDS, (byte)charC)) set_intersection(tempSet, tempSet, DUS); /* SN 3.5 */
- }
- if (charD != ' ') { /* SN 3.5 */
- if (set_member(SLS, (byte)charD)) set_intersection(tempSet, tempSet, SRS); /* SN 3.5 */
- if (set_member(DLS, (byte)charD)) set_intersection(tempSet, tempSet, DRS); /* SN 3.5 */
- }
-
- tempChar = ' '; /* SN 3.5 */
- if (!(*tempSet)) strcpy(tempSet, startSet); /* SN 3.5 */
- for(counter = 40; counter >= 0; counter--) { /* SN 3.5 */
- if (tempChar == ' ') { /* SN 3.5 */
- if (strchr(tempSet, *(LineStr + counter))) tempChar = *(LineStr + counter); /* SN 3.5 */
- }
- }
-
- return(tempChar); /* SN 3.5 */
- }
-
-
- void noise(int freq, double secs)
- {
- int duration;
-
- delay(0);
- duration = (int) floor(secs*1000);
- sound(freq);
- delay(duration);
- nosound();
- }
-
- void audible(audibletyp signal)
- {
- switch (signal) {
- case Beep :
- case Error : noise(897,0.5); break;
- case Warning : noise(200,0.05); break;
- case Pip : noise(3500,0.025); break;
- case Fluff : noise(30,0.025); break;
- }
- }
-
- void delayorkey(double secs)
- {
- word count;
-
- count = 0;
- do {
- delay(100);
- } while ((!kpressed()) && (++count < ((word) (secs*10))));
- if (kpressed()) getkey();
- }
-
-
- long maximum(long number1, long number2) /* SN 3.5 */
- { /* SN 3.5 */
- return((number1 > number2) ? number1 : number2); /* SN 3.5 */
- } /* SN 3.5 */
-
- long minimum(long number1, long number2) /* SN 3.5 */
- { /* SN 3.5 */
- return((number1 < number2) ? number1 : number2); /* SN 3.5 */
- } /* SN 3.5 */
-
-
- void fillstr(string s, int len, uchar ch)
- {
- memset(s,ch,len);
- s[len] = 0;
- }
-
- strptr decchar(string sout, string s)
- {
- byteptr sptr;
-
- sptr = (byteptr) sout;
- while (*s)
- *(sptr++) = (byte) (255-((byte) *(s++)));
- *sptr = 0;
- return (sout);
- }
-
- strptr strip(string sout, string field)
- {
- strptr sptr;
-
- sptr = sout;
- do
- if (*field != ' ') *(sptr++) = *field;
- while (*(field++));
- return (sout);
- }
-
- strptr trim(string sout, string inpstr)
- {
- int cp;
-
- cp = strlen(inpstr);
- while (cp && (inpstr[cp - 1] == ' ')) cp--;
- strncpy(sout,inpstr,cp);
- sout[cp] = 0;
- return (sout);
- }
-
- strptr mirt(string sout, string inpstr)
- {
- while (*inpstr == ' ') inpstr++;
- strcpy(sout,inpstr);
- return (sout);
- }
-
- strptr pad(string sout, string str, int size, int side)
- {
- int len,padding;
-
- len = strlen(str);
- padding = size - len;
- if (padding > 0)
- if (side == 0) {
- memmove(sout + padding,str,len+1);
- memset(sout,' ',padding);
- }
- else {
- memset(stpcpy(sout,str),' ',padding);
- sout[size] = 0;
- }
- else
- strcpy(sout,str);
- return (sout);
- }
-
- strptr centre(string sout, string str, int size)
- {
- int len,lpad,rpad;
-
- len = strlen(str);
- rpad = (size - len) / 2;
- lpad = size - len - rpad;
- if (size > len) {
- memmove(sout + lpad,str,len);
- memset(sout,' ',lpad);
- memset(sout + lpad + len,' ',rpad);
- sout[size] = 0;
- }
- else
- strcpy(sout,str);
- return (sout);
- }
-
- bool empty(string field)
- {
- while (*field == ' ') field++;
- return ((bool) (*field == 0));
- }
-
- bool no_spaces(string field)
- {
- return ((bool) (strchr(field,' ') == NULL));
- }
-
- strptr istr(string sout, long num, int s)
- {
- string tempString;
-
- sprintf(tempString,"%*ld",s,num);
- *(tempString + s) = '\0';
- strcpy(sout, tempString);
- return (sout);
- }
-
- strptr fstr(string sout, double num, int s, int d)
- {
- string tempString;
- char *commaPos;
-
- sprintf(tempString,"%*.*lf", s,d,num);
- *(tempString + s) = '\0';
- if (*_dcpt != '.') {
- commaPos = strchr(tempString, '.');
- if (commaPos) *commaPos = *_dcpt;
- }
- strcpy(sout, tempString);
- return (sout);
- }
-
- double valu(string numstr)
- {
- char *commaPos;
- string numberString;
-
- strip(numberString, numstr);
- if (*_dcpt != '.') {
- commaPos = strchr(numberString, *_dcpt);
- if (commaPos) *commaPos = '.';
- }
- return (atof(numberString));
- }
-
- long ival(string numstr)
- {
- return(atol(numstr));
- }
-
- void float_ins(uchar c, string strg)
- {
- strptr destptr;
-
- while (*strg == ' ') strg++;
- destptr = strg;
- memmove(++destptr,strg,strlen(strg) + 1);
- *strg = c;
- }
-
- bool path_ok(pathstr path)
- {
- pathstr srchpath;
- findrec frec;
-
- strcpy(srchpath,path);
- if (*srchpath && (srchpath[strlen(srchpath) - 1] != '\\')) strcat(srchpath,"\\*.*");
- else strcat(srchpath,"*.*");
- return (db_findfirst(srchpath,&frec,A_DIREC));
- }
-
- strptr parse_new_path(strptr sout, string path)
- {
- string ts;
- uchar drv[2];
- int p;
-
- strcpy(drv, " ");
- strcpy(sout,path);
- getcurrentdir(ts,0); drv[0] = ts[0];
- if (strposstr(":\\",path) != 1) {
- if (path[0] == '\\') strconcat(sout,drv,":",path,NULL);
- else if (path[1] == ':') {
- strinsert("\\",sout,2);
- if (sout[3] == '\0') getcurrentdir(sout,(byte)(sout[0]-64));
- else if (!path_ok(sout)) {
- getcurrentdir(ts,(byte)(sout[0]-64));
- strconcat(sout,ts,strcopy(sout,sout,2,strlen(sout)-2),NULL);
- }
- }
- else {
- strconcat(sout,ts,"\\",path,NULL);
- p = strposch('\\',sout);
- if (p >= 0) strdelete(sout,p,1);
- }
- }
- return(sout);
- }
-
- void makedir(string dirstr)
- /* Expects full drive and path specification */
- {
- uchar *s, *wks;
- string ts, tdirstr;
- int i, err;
-
- ts[0] = '\0';
- parse_new_path(tdirstr,strip(tdirstr,dirstr));
- s = tdirstr;
- while (s[0] && s[1]) s++;
- if (*s == '\\') *s = 0;
- err = mkdir(tdirstr);
- if (err != 0) err = errno;
- if ((err == 2) || (err == 3)) {
- while ((err == 2) || (err == 3) && (*tdirstr)){
- while ((*s != '\\') && (s != tdirstr)) s--;
- strconcat(ts,s,ts,NULL);
- *s = 0;
- err = mkdir(tdirstr);
- if (err != 0) err = errno;
- }
- wks = ts;
- while ((*wks) && (err == 0)) {
- do {
- *s++ = *wks;
- wks++;
- } while ((*wks) && (*wks != '\\'));
- *s = 0;
- err = mkdir(tdirstr);
- }
- }
- }
-
- bool pathcouldexist(string p)
- {
- uchar baddirchrs[20];
- string ts, tp;
- bool valid;
- int i;
-
- strcpy(baddirchrs, "=\"/+*.:;<>|?");
- strip(tp,p); valid = (tp[0] != '\0');
- if (valid) {
- ts[0] = '\0';
- i = strposch('\\',tp); /* Assume starts with 'X:\' */
- if (i >= 0) strdelete(tp,0,i+1); else tp[0] = '\0';
- while ((tp[0] != '\0') && (valid)) {
- i = strposch('\\',tp);
- if (i < 0) i = 0;
- strcopy(ts,tp,0,i);
- strdelete(tp,0,i+1);
- if (strlen(ts) < 9)
- valid = (strpbrk(ts,baddirchrs) == NULL);
- else
- valid = False;
- }
- }
- return(valid);
- }
-
- bool name_ok(string fname)
- {
- string tfname;
- uchar badnamechrs[20];
- bool valid;
- int i;
-
- strcpy(badnamechrs, "\"*+,./:;<=>?[\\]^|");
- valid = True;
- strcpy(tfname,fname);
- i = strposch('.',tfname);
- if (i >= 0) tfname[i] = '\0';
- i = 0;
- while ((valid) && (i < strlen(tfname))) {
- valid = (strpbrk(tfname,badnamechrs) == NULL) && (tfname[i] >= '!') && (tfname[i] <= '~');
- i++;
- }
- return(valid);
- }
-
- bool exists(pathstr fname)
- {
- return ((bool) (access(fname,0x42) == 0));
- }
-
- strptr hexs(string sout, int num, int sp)
- {
- if (num < 0) sprintf(sout,"$-%X",abs(num));
- else sprintf(sout,"$%X",num);
- pad(sout,sout,sp,Left);
- return (sout);
- }
-
- strptr hexstr(string sout, int num)
- {
- if (num < 0) sprintf(sout,"$-%X",abs(num));
- else sprintf(sout,"$%X",num);
- return (sout);
- }
-
- void allocstr(int fileHandle, strptr stringPointer) /* SN 3.5 */
- { /* SN 3.5 */
- byte stringSize; /* SN 3.5 */
- /* SN 3.5 */
- stringPointer = 0; /* SN 3.5 */
- if (read(fileHandle, &stringSize, 1) != -1) { /* SN 3.5 */
- if (stringSize) { /* SN 3.5 */
- if ((stringPointer = malloc(stringSize + 1)) != NULL) { /* SN 3.5 */
- *stringPointer = stringSize; /* SN 3.5 */
- if (read(fileHandle, (stringPointer + 1), stringSize) == -1) stringPointer = 0; /* SN 3.5 */
- } /* SN 3.5 */
- } /* SN 3.5 */
- } /* SN 3.5 */
- return; /* SN 3.5 */
- } /* SN 3.5 */
-
- void xchgstrp(strptr stringPointer, string aString) /* SN 3.5 */
- { /* SN 3.5 */
- if (stringPointer) free(stringPointer); /* SN 3.5 */
- stringPointer = malloc(strlen(aString) + 1); /* SN 3.5 */
- memcpy(stringPointer, aString, strlen(aString)); /* SN 3.5 */
- return; /* SN 3.5 */
- } /* SN 3.5 */
-
- /********************** UNIT INITIALIZATION/EXIT CODE *********************/
-
- void db_funcs_init(void)
- {
- if (!initialized) {
- initialized = True;
- db_key_init();
- /***************************************************************************
- * [DG] 09/10/92 -- Added CtrlEnter, Tab, and STab to ExitSet, allowing *
- * these keys to end field editing. *
- ***************************************************************************/
- set_addmember(ExitSet, CtrlEnter);
- set_addmember(ExitSet, Tab);
- set_addmember(ExitSet, STab);
- }
- }
-
- /**************************** END OF DB_FUNCS.C ***************************/
-